package com.example.spinning.service;

import com.example.spinning.bean.EndProductOutStock;
import com.example.spinning.mapper.EndProductOutStockMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EndProductOutStockService {

    @Autowired
    private EndProductOutStockMapper endProductOutStockMapper;

    //得到出库单信息
    //带有分页功能的展现数据
    public List<EndProductOutStock> getAllOutStock(Integer page, Integer count) {
        int start = (page - 1) * count;
        return endProductOutStockMapper.getEndProductOutStock(start,count);
    }

    //找到行数
    public int getOutStockCount() {
        return endProductOutStockMapper.getCountEndProductOutStock();
    }

    //根据条件找到行数
    public int getOutStockCountByCondition(String date,String receiver,String norms,String batch_no) {
        return endProductOutStockMapper.getCountEndProductOutStockByCondition(date,receiver,norms,batch_no);
    }

    //根据id查询出库单信息
    public EndProductOutStock getOutStockById(long id){
        EndProductOutStock stock = endProductOutStockMapper.getEndProductOutStockById(id);
        return stock;
    }

    //根据条件模糊查询
    public List<EndProductOutStock> getOutStockByCondition(Integer page, Integer count,String date,String receiver,String norms,String batch_no){
        int start = (page - 1) * count;
        return endProductOutStockMapper.getEndProductOutStockByCondition(start,count,date,receiver,norms,batch_no);
    }

    //添加出库单信息
    public int addOutStock(EndProductOutStock stock){
        return endProductOutStockMapper.addEndProductOutStock(stock);
    }


    //修改
    public int updateOutStock(EndProductOutStock stock){
        return endProductOutStockMapper.updateEndProductOutStockById(stock);
    }

    //删除
    public boolean deleteOutStockByIds(String ids){
        String[] split = ids.split(",");
        int result = endProductOutStockMapper.delEndProductOutStockById(split);
        return result == split.length;
    }


}
